implement the bounds method correctly. (compute_viewport_affine): compute
authorLarry Ewing <lewing@gimp.org>
Wed, 17 Nov 1999 23:21:34 +0000 (23:21 +0000)
committerLarry Ewing <lewing@src.gnome.org>
Wed, 17 Nov 1999 23:21:34 +0000 (23:21 +0000)
1999-11-17  Larry Ewing  <lewing@gimp.org>

* src/gnome-canvas-pixbuf.c (gnome_canvas_pixbuf_bounds):
implement the bounds method correctly.
(compute_viewport_affine): compute the affine need to fit the
image within the viewport given by the args.
(compute_render_affine): call compute_viewport_affine.

gdk-pixbuf/ChangeLog
gdk-pixbuf/gnome-canvas-pixbuf.c

index 78196f360fed8d35dd6b68bd15dd951c2090d431..322a1ba4b693bd53cba7fa04fa982c450f53c450 100644 (file)
@@ -1,3 +1,11 @@
+1999-11-17  Larry Ewing  <lewing@gimp.org>
+
+       * src/gnome-canvas-pixbuf.c (gnome_canvas_pixbuf_bounds):
+       implement the bounds method correctly.
+       (compute_viewport_affine): compute the affine need to fit the 
+       image within the viewport given by the args.
+       (compute_render_affine): call compute_viewport_affine.
+
 1999-11-16  Havoc Pennington  <hp@pobox.com>
 
        * src/gdk-pixbuf-drawable.h: Use includes from the current
index 52b445d13635261d1493904573cf19a6eb3e96d8..1504e96c4e708cecd5c223b880a8e4f8e3131eb3 100644 (file)
@@ -454,20 +454,19 @@ compute_xform_scaling (double *affine, ArtPoint *i_c, ArtPoint *j_c)
        j_c->y -= orig_c.y;
 }
 
-/* Computes the affine transformation with which the pixbuf needs to be
- * transformed to render it on the canvas.  This is not the same as the
- * item_to_canvas transformation because we may need to scale the pixbuf by some
- * other amount.
+/* computes the addtional resolution dependent affine needed to
+ * fit the image within its viewport defined by x,y,width and height
+ * args
  */
 static void
-compute_render_affine (GnomeCanvasPixbuf *gcp, double *render_affine, double *i2c)
+compute_viewport_affine (GnomeCanvasPixbuf *gcp, double *viewport_affine, double *i2c)
 {
        PixbufPrivate *priv;
        ArtPoint i_c, j_c;
        double i_len, j_len;
        double si_len, sj_len;
        double ti_len, tj_len;
-       double scale[6], translate[6], composite[6];
+       double scale[6], translate[6];
        double w, h;
        double x, y;
 
@@ -548,8 +547,21 @@ compute_render_affine (GnomeCanvasPixbuf *gcp, double *render_affine, double *i2
 
        art_affine_scale (scale, si_len, sj_len);
        art_affine_translate (translate, ti_len, tj_len);
-       art_affine_multiply (composite, scale, translate);
-       art_affine_multiply (render_affine, composite, i2c);
+       art_affine_multiply (viewport_affine, scale, translate);
+}
+
+/* Computes the affine transformation with which the pixbuf needs to be
+ * transformed to render it on the canvas.  This is not the same as the
+ * item_to_canvas transformation because we may need to scale the pixbuf 
+ * by some other amount.
+ */
+static void
+compute_render_affine (GnomeCanvasPixbuf *gcp, double *render_affine, double *i2c)
+{
+       double viewport_affine[6];
+       
+       compute_viewport_affine (gcp, viewport_affine, i2c);
+       art_affine_multiply (render_affine, viewport_affine, i2c);
 }
 
 /* Recomputes the bounding box of a pixbuf canvas item.  The horizontal and
@@ -809,25 +821,29 @@ gnome_canvas_pixbuf_bounds (GnomeCanvasItem *item, double *x1, double *y1, doubl
 {
        GnomeCanvasPixbuf *gcp;
        PixbufPrivate *priv;
+       double i2c[6], viewport_affine[6];
+       ArtDRect rect;
 
        gcp = GNOME_CANVAS_PIXBUF (item);
        priv = gcp->priv;
 
-       *x1 = 0.0;
-       *y1 = 0.0;
+       if (!priv->pixbuf) {
+               *x1 = *y1 = *x2 = *y2 = 0.0;
+               return;
+       }
 
-       if (priv->pixbuf) {
-               if (priv->width_set)
-                       *x2 = priv->width;
-               else
-                       *x2 = priv->pixbuf->art_pixbuf->width;
+       rect.x0 = 0.0;
+       rect.x1 = priv->pixbuf->art_pixbuf->width;
 
-               if (priv->height_set)
-                       *y2 = priv->height;
-               else
-                       *y2 = priv->pixbuf->art_pixbuf->height;
-       } else {
-               *x2 = 0.0;
-               *y2 = 0.0;
-       }
+       rect.y0 = 0.0;
+       rect.y1 = priv->pixbuf->art_pixbuf->height;
+       
+       gnome_canvas_item_i2c_affine (item, i2c);
+       compute_viewport_affine (gcp, viewport_affine, i2c);
+       art_drect_affine_transform (&rect, &rect, viewport_affine);
+
+       *x1 = rect.x0;
+       *y1 = rect.y0;
+       *x2 = rect.x1;
+       *y2 = rect.y1;
 }